<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>post请求的发送</title>
    <style>
        .container {
            width: 200px;
            height: 200px;
            border: 1px solid red;
        }
    </style>
</head>
<body>
    <div class="container"></div>
    <script>
        var container = document.querySelector('.container');
        container.onmouseover = function () {
            const xhr = new XMLHttpRequest();
            xhr.open('POST','http://localhost:8000/server');
            //设置请求头信息
            xhr.setRequestHeader('name','cty');//发送自定义信息
            //post方式设置请求体 发送什么样的参数都可以 只要服务端能解析
            // xhr.send();
            xhr.send('a=100&b=300');
            xhr.onreadystatechange = function () {
                if (xhr.readyState === 4) {
                    if (xhr.status >= 200 && xhr.status < 300) {
                        container.innerHTML = xhr.response;
                    }
                }
            }
        }
    </script>
</body>
</html>